* TABLE 112 in Appendix - racial distribution
qui{
clear
use "${data}/MEPS_merged_Health_all_races.dta"

keep if AGE1>=25 & AGE1<=64
table RACE_sum educ_group [aw=Sample_Weight], statistic(percent)  nformat(%5.1f)

collect title "Statistics on Race, Males, ages 25-64, MEPS"
collect style header RACE_sum, title(hide)
collect export "${out_tables}/Races_distribution.tex", tableonly replace
}

**** Health regressions 
* Tables 113-114 and 127 in Appendix 
qui{
clear
use "${data}/MEPS_merged_Health_all_races.dta"
keep if educ_group==1

gen AGE_CUB_YR1 = AGE_YR1^3
drop if year==2013
gen AGE_CUB_YR2 = AGE_YR2^3

gen I_time_period=0 if year<=2007
replace I_time_period=1 if year>2007 //  

keep if INSCOP_Y2==1 // this covers R3-R5 which we are using here.
drop if INSCOV_Y1==. | INSCOV_Y2==.

gen H_trans5=0 if H1==3 & (H3==1 | H3==2)  //stay in good H
replace H_trans5=1 if H1==3 & H3==3 // stay in good

gen R_trans=0 if R3==0 & R5==0
replace R_trans=1 if R3==0 & R5==1


* Table 113 Appendix - logit good health 

gen H_good=1 if H1==3
replace H_good=0 if H1!=3 & H1!=. 

label var H_good "Good H"

    logit H_good i.RACE_sum AGE_YR1 AGE_SQ_YR1 AGE_CUB_YR1   if  ( AGE_YR1>=25 & AGE_YR1<65) [pw=Sample_Weight]
	eststo
    logit H_good i.RACE_sum AGE_YR1 AGE_SQ_YR1 AGE_CUB_YR1 i.INSCOV_Y1 if  ( AGE_YR1>=25 & AGE_YR1<65) [pw=Sample_Weight]
	eststo
	logit H_good i.RACE_sum AGE_YR1 AGE_SQ_YR1 AGE_CUB_YR1 if  (INSCOV_Y1==1  & AGE_YR1>=25 & AGE_YR1<65) [pw=Sample_Weight]
	eststo
	logit H_good i.RACE_sum AGE_YR1 AGE_SQ_YR1 AGE_CUB_YR1 if  (INSCOV_Y1!=1  & AGE_YR1>=25 & AGE_YR1<65) [pw=Sample_Weight]
	eststo
		esttab using "${out_tables}/H_initial_reg_race3_HS.tex", varwidth(25) nogaps   compress label nobaselevels indicate( "Cubic Age = *AGE_YR1* *AGE_SQ_YR1* *AGE_CUB_YR1* " ) replace  ///
	nodepvars nonumbers eqlabel(none) noconstant mtitles("All" "All" "Has PHI" "No PHI") star(* 0.1 ** 0.05 *** 0.01) ///
	se   b(3) pr2
	eststo clear
	
	
* Table 114 Appendix - keeping good H	

label var H_trans5 "Keep Good H"	
	
	*keep if I_time_period==1
		logit H_trans5 i.RACE_sum AGE_YR1 AGE_SQ_YR1 AGE_CUB_YR1  i.dp i.du  if  ( AGE_YR1>=25 & AGE_YR1<65)
	eststo
	logit H_trans5 i.RACE_sum AGE_YR1 AGE_SQ_YR1 AGE_CUB_YR1  i.dp i.du i.INSCOV_Y1 if  ( AGE_YR1>=25 & AGE_YR1<65)
	eststo
	logit H_trans5 i.RACE_sum AGE_YR1 AGE_SQ_YR1 AGE_CUB_YR1  i.dp i.du if  (INSCOV_Y1==1 & INSCOV_Y2==1 & AGE_YR1>=25 & AGE_YR1<65)
	eststo
	logit H_trans5 i.RACE_sum AGE_YR1 AGE_SQ_YR1 AGE_CUB_YR1  i.dp i.du if  (INSCOV_Y1!=1 & INSCOV_Y2!=1 & AGE_YR1>=25 & AGE_YR1<65)
	eststo
	esttab using "${out_tables}/H_initial_reg_race2_HS.tex", varwidth(25) nogaps   compress label nobaselevels indicate( "Cubic Age = *AGE_YR1* *AGE_SQ_YR1* *AGE_CUB_YR1* " ) replace  ///
	nodepvars nonumbers eqlabel(none) noconstant mtitles("All" "All" "Has PHI" "No PHI") star(* 0.1 ** 0.05 *** 0.01) ///
	se   b(3) pr2
	eststo clear
	
	
	* Table 127 Appendix, left panel. 
	
	* SHOW THESE IN CALIBRATION FOR RACES
		logit H_trans5 i.RACE_sum AGE_YR1 AGE_SQ_YR1 AGE_CUB_YR1  i.dp i.du if  (INSCOV_Y1==1 & INSCOV_Y2==1 & AGE_YR1>=25 & AGE_YR1<65) [pw=Sample_Weight]
 eststo margin: margins i.RACE_sum, at(AGE_YR1=45  AGE_SQ_YR1=2025 AGE_CUB_YR1=91125  ) atmeans post
 est sto h1
	logit H_trans5 i.RACE_sum AGE_YR1 AGE_SQ_YR1 AGE_CUB_YR1  i.dp i.du if  (INSCOV_Y1!=1 & INSCOV_Y2!=1 & AGE_YR1>=25 & AGE_YR1<65) [pw=Sample_Weight]
 eststo margin:	 margins i.RACE_sum, at(AGE_YR1=45  AGE_SQ_YR1=2025 AGE_CUB_YR1=91125  ) atmeans post
 est sto h2
	esttab h1  h2  using "${out_tables}/H_trans_race_HS.tex", varwidth(25) nogaps   compress label replace  ///
	 nonumbers mtitles("Has ESHI"  "No ESHI" ) nostar ///
	se   b(3) 
	eststo clear
}
	

	
* TABLE 115 Appendix. 	
qui{
clear
use "${data}/MEPS_merged_Health_all_races.dta"

keep if educ_group==1
keep if AGE_YR1>=25 & AGE_YR1<65

gen AGE_CUB_YR1 = AGE_YR1^3
gen AGE_CUB_YR2 = AGE_YR2^3

gen I_time_period=0 if year<=2007
replace I_time_period=1 if year>2007 //  
drop if INSCOV_Y1==. 

	gen AGE_SQ_YR1_use = AGE_SQ_YR1/100
	gen AGE_CUB_YR1_use=AGE_CUB_YR1/10000

keep if I_time_period==1

logit dp i.RACE_sum i.H1  AGE_YR1 AGE_SQ_YR1_use AGE_CUB_YR1_use  i.INSCOV_Y1 i.year if  ( AGE_YR1>=25 & AGE_YR1<65) [pw=Sample_Weight]
	eststo
logit du i.RACE_sum i.H1  AGE_YR1 AGE_SQ_YR1_use AGE_CUB_YR1_use  i.INSCOV_Y1 i.year if  ( AGE_YR1>=25 & AGE_YR1<65) [pw=Sample_Weight]
	eststo
logit s i.RACE_sum i.H1  AGE_YR1 AGE_SQ_YR1_use AGE_CUB_YR1_use  i.INSCOV_Y1 i.year if  ( AGE_YR1>=25 & AGE_YR1<65) [pw=Sample_Weight]
	eststo	
logit R3 i.RACE_sum   AGE_YR1 AGE_SQ_YR1_use AGE_CUB_YR1_use  i.INSCOV_Y1  i.year if  ( AGE_YR1>=25 & AGE_YR1<65) [pw=Sample_Weight]
	eststo	
		esttab using "${out_tables}/Shocks_race_table_HS.tex", varwidth(25) nogaps   compress label nobaselevels indicate("Health (H) = *H1*"  "Cubic Age = *AGE_YR1* *AGE_SQ_YR1_use* *AGE_CUB_YR1_use* " "Year Dummies = *year*") replace  ///
	nodepvars nonumbers eqlabel(none) noconstant mtitles("\$d^p\$" "\$d^u\$" "\$s\$" "\$R\$") star(* 0.1 ** 0.05 *** 0.01) ///
	se   b(3) pr2
	eststo clear		
}	
	
		
	
* Tables 116 and 117 in Appendix. 
qui{
clear
use "${data}/MEPS_merged_Health_all_races.dta"
keep if AGE1<65 & AGE1>24
keep if educ_group==1
keep if INSCOP_Y1==1 // this covers R1-R3 which we are using here.

gen I_Charges = 1 if Charges_plus_RX<.5 & Charges_plus_RX!=.
replace I_Charges = 0 if Charges_plus_RX>=.5 & Charges_plus_RX!=.

gen I_EXP = 1 if Expenditures_incl_RX<.5 & Expenditures_incl_RX!=.
replace I_EXP = 0 if Expenditures_incl_RX>=.5 & Expenditures_incl_RX!=.

gen I_suspicious1 = 1 if Charges_plus_RX<Expenditures_incl_RX & Expenditures_incl_RX!=. & Charges_plus_RX!=.
replace I_suspicious1 = 0 if Charges_plus_RX>=Expenditures_incl_RX & Expenditures_incl_RX!=. & Charges_plus_RX!=.


gen PHI=0 if INSCOV_Y1==2 | INSCOV_Y1==3
replace PHI=1 if INSCOV_Y1==1



* Table 116 in Appendix. 
*** LOGIT FOR THIS TO CONTROL FOR EVERYTHING
	logit I_Charges i.RACE_sum AGE_YR1 AGE_SQ_YR1  i.H1 i.type2  if PHI==1 & I_suspicious1 == 0 & ( dp==1 | du==1) [pw=Sample_Weight]
eststo margin: margins i.RACE_sum , atmeans post
est sto h1
	logit I_Charges i.RACE_sum AGE_YR1 AGE_SQ_YR1  i.H1 i.type2 if PHI==0 & I_suspicious1 == 0 & ( dp==1 | du==1) [pw=Sample_Weight]
eststo margin: margins i.RACE_sum , atmeans post
est sto h2
	esttab h1 h2  using "${out_tables}/Logit_negligible_charges_RACE_HS.tex", varwidth(25) nogaps   compress label replace  ///
	 nonumbers mtitles("ESHI" "No ESHI") nostar ///
	se   b(3) 
	eststo clear


* Table 117 in Appendix	
		reg Charges_plus_RX i.RACE_sum AGE_YR1 AGE_SQ_YR1  i.H1##i.type2  i.year if PHI==1 & I_suspicious1 == 0 & ( dp==1 | du==1 | s==1) & I_Charges == 0  [pw=Sample_Weight]
		eststo
		reg Charges_plus_RX i.RACE_sum AGE_YR1 AGE_SQ_YR1  i.H1##i.type2   i.year if PHI==0 & I_suspicious1 == 0 & ( dp==1 | du==1  | s==1) & I_Charges == 0  [pw=Sample_Weight]
		eststo
		reg TOTSLF_Y1       i.RACE_sum AGE_YR1 AGE_SQ_YR1  i.H1##i.type2  i.year if PHI==1 & I_suspicious1 == 0 & ( dp==1 | du==1  | s==1) & I_Charges == 0  [pw=Sample_Weight]
		eststo
		reg TOTSLF_Y1 i.RACE_sum AGE_YR1 AGE_SQ_YR1  i.H1##i.type2   i.year if PHI==0 & I_suspicious1 == 0 & ( dp==1 | du==1  | s==1) & I_Charges == 0  [pw=Sample_Weight]
		eststo	
				esttab using "${out_tables}/Charges_OOP_race_HS.tex", varwidth(25) nogaps   compress label nobaselevels indicate("H, shocks, H*shocks = *H1* *type2* " "Age, Age sq. = *AGE_YR1* *AGE_SQ_YR1* " "Year Dummies = *year*") replace  ///
	nodepvars nonumbers eqlabel(none) noconstant mtitles("Charges, Has ESHI" "Charges, No ESHI" "OOP, Has ESHI" "OOP, No ESHI") star(* 0.1 ** 0.05 *** 0.01) ///
	se   b(3) 
	eststo clear
}	
	

	
	

****** R by age - save data for figures against model data
qui{
clear
use "${data}/MEPS_merged_Health_all_races.dta"
keep if  AGE_YR2<65 //  
drop if R5==.
drop if AGE_YR2==.
keep if INSCOP_Y2==1 // this covers R3-R5 which we are using here.
keep if year>=2007  

drop if INSCOV_Y1==1 & labor_force_Y2==1
keep if educ_group==1

collapse (mean) R3 R5, by(AGE_YR2 RACE_sum)
rename  AGE_YR2 age
keep if RACE_sum==2 | RACE_sum==3
sort RACE_sum age
save "${data}\R_ages_ALL_races.dta",  replace
}

* shocks, R and H by age and education - save data for Figure 33 Appendix  
qui{
clear
use "${data}/MEPS_merged_Health_all_races.dta"
keep if educ_group==1

keep if INSCOP_Y1==1
rename AGE_YR1 age
gen H_1=0 
replace H_1=1 if H1==1
gen H_2=0 
replace H_2=1 if H1==2
gen H_3=0 
replace H_3=1 if H1==3

* age groups
gen age_group=27  if age>=25 & age<30
replace age_group=32  if age>=30 & age<35
replace age_group=37  if age>=35 & age<40
replace age_group=42  if age>=40 & age<45
replace age_group=47  if age>=45 & age<50
replace age_group=52  if age>=50 & age<55
replace age_group=57  if age>=55 & age<60
replace age_group=62  if age>=60 & age<65
replace age_group=67  if age>=65 & age<70
replace age_group=72  if age>=70 & age<75
replace age_group=77  if age>=75 & age<80
replace age_group=82  if age>=80 & age<85
replace age_group=87  if age>=85 & age<90
replace age_group=92  if age>=90 & age<95
replace age_group=97  if age>=95 & age<101
label var age_group "Age Group"

replace R3=. if  year<=2006
replace dp=. if  year<=2006
replace du=. if  year<=2006
replace s=. if  year<=2006

collapse R3 dp du s H_1 H_2 H_3, by(age  RACE_sum)
sort age
rename R3 R_data
rename dp dp_data
rename du du_data
rename s s_data
rename H_1 H_1_data
rename H_2 H_2_data
rename H_3 H_3_data
replace dp_data=dp_data*100
replace R_data=R_data*100
replace H_1_data=H_1_data*100
replace H_2_data=H_2_data*100
replace H_3_data=H_3_data*100
replace du_data=du_data*100
replace s_data=s_data*100
rename age age_group
keep if RACE_sum==2 | RACE_sum==3
sort RACE_sum age_group
save "${data}/Health Moments 2 data Races.dta",  replace
}


* save data for Figure 36 
qui{
clear
use "${data}/MEPS_merged_Health_all_races.dta"
drop if year==2013
keep if INSCOP_Y2==1 // this covers R3-R5 which we are using here.
keep if educ_group==1
// from good to bad
gen H_trans=1 if (H1==3 ) & H3==3 // stay in good
replace H_trans=0 if H1==3 & (H3==2 | H3==1)  // transition to worse health

gen d_shock=1 if dp==1 | du==1
replace d_shock=0 if dp==0 & du==0

drop if H1==. | H3==.
keep if AGE_YR1>=25 & AGE_YR1<75

rename AGE_YR1 age

* age groups
gen age_group=27  if age>=25 & age<30
replace age_group=32  if age>=30 & age<35
replace age_group=37  if age>=35 & age<40
replace age_group=42  if age>=40 & age<45
replace age_group=47  if age>=45 & age<50
replace age_group=52  if age>=50 & age<55
replace age_group=57  if age>=55 & age<60
replace age_group=62  if age>=60 & age<65
replace age_group=67  if age>=65 & age<70
replace age_group=72  if age>=70 & age<75

collapse (mean) GG=H_trans, by(age_group d_shock RACE_sum) 
rename age_group age
keep if RACE_sum==2 | RACE_sum==3
sort RACE_sum  age d_shock
save "${data}/Health Trans Moments data shocks races.dta",  replace
}

* H transitions -- Figure 35
* we save these transitions and then plot them together with the ones from the model in figures in H transitions section of Appendix. 
qui{ 
clear
use "${data}/MEPS_merged_Health_all_races.dta"
drop if year==2013
keep if educ_group==1

keep if INSCOP_Y2==1 // this covers R3-R5 which we are using here.

// from good to bad
gen H_trans=0 if (H1==3 ) & H3==3 // stay in good
replace H_trans=1 if H1==3 & (H3==2 | H3==1)  // transition to worse health

// from bad to good
gen H_trans1=0 if  (H1==2 | H1==1) &  (H3==2 | H3==1)
replace H_trans1=1 if (H1==2 | H1==1) &  H3==3 

// from poor to better
gen H_trans2=0 if  ( H1==1) &  ( H3==1)
replace H_trans2=1 if (H1==1) &  (H3==3 | H3==2)

// from poor to poor
gen H_trans3=0 if  ( H1==1) &  ( H3!=1 & H3!=.)
replace H_trans3=1 if (H1==1) &  (H3==1)

// from fair to fair
gen H_trans4=0 if  ( H1==2) &  ( H3!=2 & H3!=.)
replace H_trans4=1 if (H1==2) &  (H3==2)

// from good to good
gen H_trans5=0 if  ( H1==3) &  ( H3!=3 & H3!=.)
replace H_trans5=1 if (H1==3) &  (H3==3)

// from fair/good to poor
gen H_trans6=0 if  ( H1==3 | H1==2) &  ( H3==1)
replace H_trans6=1 if ( H1==3 | H1==2) &  ( H3!=1 & H3!=.)


drop if H1==. | H3==.
keep if AGE_YR1>=25 & AGE_YR1<75

rename AGE_YR1 age

* age groups
gen age_group=27  if age>=25 & age<30
replace age_group=32  if age>=30 & age<35
replace age_group=37  if age>=35 & age<40
replace age_group=42  if age>=40 & age<45
replace age_group=47  if age>=45 & age<50
replace age_group=52  if age>=50 & age<55
replace age_group=57  if age>=55 & age<60
replace age_group=62  if age>=60 & age<65
replace age_group=67  if age>=65 & age<70
replace age_group=72  if age>=70 & age<75

collapse (mean) GB=H_trans BG=H_trans1  PG=H_trans2  PP=H_trans3  FF=H_trans4  GG=H_trans5 FGP=H_trans6, by(RACE_sum age_group) 
//reshape wide GB BG PG PP FF GG FGP, i(age_group) j(educ_group)
rename age_group age
keep if RACE_sum==2 | RACE_sum==3
sort RACE_sum age
save "${data}/Health Trans Moments data races.dta",  replace
}


* H by ESHI  - for Figure 37, RHS panels
qui{
clear
use "${data}/MEPS_merged_Health_all_races.dta"
keep if educ_group==1
keep if INSCOP_Y1==1
rename AGE_YR1 age

gen H_1=0 
replace H_1=1 if H1==1
gen H_2=0 
replace H_2=1 if H1==2
gen H_3=0 
replace H_3=1 if H1==3

keep if age<65 

rename PRIVATE_HI_Y1 ESHI

drop if ESHI==.
collapse H_1 H_2 H_3, by(age RACE_sum ESHI)
rename H_1 H_1_data
rename H_2 H_2_data
rename H_3 H_3_data
sort RACE_sum age
//reshape wide H_1_data H_2_data H_3_data, i(age ESHI) j(education)
reshape wide H*, i(age RACE_sum) j(ESHI)
sort RACE_sum age
save "${data}/Health Moments 3 data races.dta",  replace
}


* H by employment - for Figure 37, LHS panels
qui{
clear
use "${data}/MEPS_merged_Health_all_races.dta"
keep if INSCOP_Y1==1
rename AGE_YR1 age
keep if educ_group==1

gen H_1=0 
replace H_1=1 if H1==1
gen H_2=0 
replace H_2=1 if H1==2
gen H_3=0 
replace H_3=1 if H1==3

keep if age<65 

gen employed_yn=0 if EMP_Y1==0
replace employed_yn=1 if EMP_Y1==1 | EMP_Y1==2

collapse H_1 H_2 H_3, by(age RACE_sum employed_yn)

rename H_1 H_1_data
rename H_2 H_2_data
rename H_3 H_3_data
sort RACE_sum age
//reshape wide H_1_data H_2_data H_3_data, i(age employed_yn) j(education)
drop if employed_yn==.
reshape wide H*, i(RACE_sum age) j(employed_yn)
sort RACE_sum age
save "${data}/Health Moments 6 data races.dta",  replace
}


**** MEDICAL CHARGES - INSURED VS UNINSURED. - for Figure 38
qui{
clear
use "${data}/MEPS_merged_Health_all_races.dta"
rename RACE_sum race
keep if educ_group==1
keep if AGE1<65
drop if AGE1==24
keep if INSCOP_Y1==1 // this covers R1-R3 which we are using here.

gen I_suspicious1 = 1 if Charges_plus_RX<Expenditures_incl_RX & Expenditures_incl_RX!=. & Charges_plus_RX!=.
replace I_suspicious1 = 0 if Charges_plus_RX>=Expenditures_incl_RX & Expenditures_incl_RX!=. & Charges_plus_RX!=.
tab  I_suspicious1
keep if  I_suspicious1 == 0 & H1!=. & Charges_plus_RX!=. 

gen MCAID_yr1= 0 if MCAID1==0 & MCAID2==0 & MCAID3==0 
replace MCAID_yr1= 1 if MCAID1==1 | MCAID2==1 | MCAID3==1
replace INSCOV_Y1=2 if INSCOV_Y1==1 & MCAID_yr1== 1 // if they had Medicaid anytime during the year, make the replacement.
	
		
preserve
collapse (mean)	Charges_plus_RX, by(age_group2 race)
rename age_group2 age_group
reshape wide Charges_plus_RX, i(age_group) j(race)
drop if age_group==65
replace age_group=age_group+2
save "${data}/Charges Moments 1 data Races.dta",  replace
restore 

preserve 
collapse (mean)	Charges_plus_RX, by(age_group2 INSCOV_Y1 race)
rename age_group2 age_group	
reshape wide Charges_plus_RX, i(age_group race) j(INSCOV_Y1)
drop if age_group==65
replace age_group=age_group+2
sort  age_group race
save "${data}/Charges Moments 2 data Races.dta",  replace
restore

preserve 
collapse (mean)	Charges_plus_RX, by(age_group2 INSCOV_Y1_alt race)
rename age_group2 age_group	
drop if INSCOV_Y1_alt==.
reshape wide Charges_plus_RX, i(age_group race) j(INSCOV_Y1_alt)
drop if age_group==65
replace age_group=age_group+2
sort age_group race
save "${data}/Charges Moments 3 data Races.dta",  replace
restore 


collapse (mean)	Charges_plus_RX, by(age_group2 race)
rename age_group2 age_group	
drop if age_group==65
replace age_group=age_group+2
sort age_group race
save "${data}/Charges Moments 5 data Races.dta",  replace	
}



* stats for access to care - main tables conditional on uninsured and has observed shock
* TABLES 128 AND 129 WITH TREATMENT AND PAYMENT RATES
qui{
clear
use "${data}/MEPS_merged_Health_all_races.dta"
rename RACE_sum race
keep if educ_group==1
keep if AGE1<65 & AGE1>24
keep if INSCOP_Y1==1 // this covers R1-R3 which we are using here.

gen ESHI=0 if INSCOV_Y1==2 | INSCOV_Y1==3 //| EMP_Y1==0 
replace ESHI=1 if INSCOV_Y1==1 & EMP_Y1!=0 
drop if EMP_Y1==.

drop if PUB1==1 | PUB2==1 | PUB3==1 // change from private to public if the person had public any time. 
drop if H1==.


keep if ESHI==0	 // keeping those completely uninsured
drop if Charges_plus_RX==. 
drop if TOTSLF_Y1==.

keep if I_any_shock==1
//keep if dp==1 | du==1

* we assume you pay if you have OOP higher or equal to 75% of .6xCharges
gen I_pay=0 if TOTSLF_Y1<.6*.75*Charges_plus_RX 
replace I_pay=1 if TOTSLF_Y1>=.6*.75*Charges_plus_RX 

* generate treatment equal to 1 if charges are higher than $500/year (note the variable is in thousands)
gen I_treat=0 if Charges_plus_RX<.5
replace I_treat=1 if Charges_plus_RX>=.5 

bysort race: egen mean_OOP= total(TOTSLF_Y1) if Charges_plus_RX>=.5 
bysort race: egen mean_MC= total(Charges_plus_RX*.6) if Charges_plus_RX>=.5
gen ratio=mean_OOP/mean_MC

	
* TABLE WITH 3 THINGS, LIMITING TO THE COMPLETELY UNINSURED WITH REPORTED SHOCK
* 1. % WITH MC<$500
* 2. % WITH OOP<.6*MC IF MC>500
* 3. mean(OOP)/mean(MC) IF MC>500 	

replace I_pay=. if Charges_plus_RX<0.500 // I_pay is conditional on treatment

//table H1 , c(mean I_negligible_MC  mean I_not_pay mean  ratio)	

label var ratio "OOP/(Charges*0.6) if treat"
label var I_treat "% treat"
label var I_pay "% pay if treat"

* TABLE 128
gen All=1
table  race ,  statistic(mean I_treat) statistic(mean I_pay) statistic(mean ratio)  nototals nformat(%5.2f)  
collect title "MEPS Data"
collect export "${out_tables}/MC_stats_races.tex", tableonly replace


* TABLE 129
drop ratio
bysort race H1: egen total_OOP= total(TOTSLF_Y1) if Charges_plus_RX>=.5
bysort race H1: egen total_MC= total(Charges_plus_RX*.6) if Charges_plus_RX>=.5
 gen ratio=total_OOP/total_MC
 label var ratio "OOP/(Charges*0.6) if treat"

table   (race H1),  statistic(mean I_treat) statistic(mean I_pay) statistic(mean ratio)  nototals nformat(%5.2f)  
collect title "MEPS Data"
collect style header H1, title(hide)
collect style header race, title(hide)
collect export "${out_tables}/MC_stats_H_races.tex", tableonly replace


}




